package com.liao.harmony.base;

import com.liao.library.ability.ComponentAbility;
import com.liao.library.lifecycle.viewmodel.ViewModelProvider;
import ohos.aafwk.content.Intent;

public abstract class BaseVMAbility<VM extends BaseViewModel> extends ComponentAbility {
    protected String TAG = this.getClass().getSimpleName();
    protected VM mViewModel;

    @SuppressWarnings("unchecked")
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(getUIContent());
        VM vm = createViewModel();
        mViewModel = (VM) new ViewModelProvider(this,BaseViewModel.createViewModelFactory(vm)).get(vm.getClass());

        init(intent);
    }

    /**
     * 获取布局id
     * @return
     */
    protected abstract int getUIContent();

    /**
     * 获取ViewModel实例
     * @return
     */
    protected abstract VM createViewModel();

    /**
     * 初始化
     */
    protected abstract void init(Intent intent);
}
